package com.dhnsoft.boot.core.service;

import com.dhnsoft.boot.core.entity.User;
import com.dhnsoft.boot.core.event.LoginSuccessEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-09-05 17:45
 * @Desc
 */
@Service
public class CouponService {

    @EventListener
    public void onEvent(LoginSuccessEvent loginSuccessEvent){
        System.out.println("=======CouponService ======感知到事件"+loginSuccessEvent);
        User source = (User) loginSuccessEvent.getSource();
        sendCoupon(source.getUsername());
    }

    public void sendCoupon(String username){
        System.out.println(username+"随机收到了一张优惠券");
    }

}
